package wwl.lsf;

/**
 * @Title
 * @Author wangwenliang
 * @Date 2020/5/29
 * @Description
 */
public class 数组中重复的数字 {

    public static void main(String[] args) {

        int[] arrs = {2,3,5,6,4,3,1};
        System.out.println(getRepeatNumber(arrs));

    }

    public static int getRepeatNumber(int[] nums ) {

        for (int i = 0; i < nums.length; i++) {

            if (nums[i] == i) {
                continue;
            }
            if (nums[i] == nums[nums[i]]) {
                return nums[i];
            }
            //交换到对应位置
            int temp = nums[i];
            nums[i] = nums[temp];
            nums[temp] = temp;

        }
        return -1;
    }
}
